import 'package:get/get.dart';
import 'package:homemedia/model/media.dart';
import 'package:homemedia/util/http/http.dart';
import 'package:homemedia/util/log_util.dart';

class LibraryLogic extends GetxController {

  final RxString uuid = RxString("");
  final RxnInt source = RxnInt(0);
  final RxList<MediaLibraryItem> items = RxList([]);

  @override
  void onReady() {
    super.onReady();
    var args = Get.arguments;
    uuid.value = args["uuid"];
    source.value = args["source"];
    initData();
  }

  initData() async{
    var result = await Http.get("/v1/media/library/items?libraryUuid=${uuid.value}", queryParameters: {}, isLoading: false);
    for (var value in (result as List)) {
      MediaLibraryItem library = MediaLibraryItem.fromJson(value as Map<String, dynamic>);
      items.add(library);
    }
    update();
  }
}
